// The Vue build version to load with the `import` command
// (runtime-only or standalone) has been set in webpack.base.conf with an alias.
import Vue from 'vue';
import App from './App';
import router from './router';
import ElementUI from 'element-ui';
import 'element-ui/lib/theme-chalk/index.css';
import Avue from '@smallwei/avue';
import '@smallwei/avue/lib/theme-chalk/index.css';
import echarts from 'echarts'

Vue.prototype.$echarts = echarts
require('./mock/mock.js')

const debounce = (func, time, ctx) => {
  let timer
  console.log(time)
  const rtn = (...params) => {
      clearTimeout(timer)
      timer = setTimeout(() => {
          func.apply(ctx, params)
      }, time)
  }
  return rtn
}

Vue.component('Debounce', {
  name: 'Debounce',
  abstract: true,
  props: ['time', 'events'],
  created () {
    this.eventKeys = this.events.split(',')
    this.originMap = {}
    this.debouncedMap = {}
  },
  render() {
      const vnode = this.$slots.default[0]
      this.eventKeys.forEach((key) => {
          const target = vnode.data.on[key]
          if (target === this.originMap[key] && this.debouncedMap[key]) {
              vnode.data.on[key] = this.debouncedMap[key]
          } else if (target) {
              this.originMap[key] = target
              this.debouncedMap[key] = debounce(target, this.time, vnode)
              vnode.data.on[key] = this.debouncedMap[key]
          }
      })
      
      return vnode
  },
})


Vue.config.productionTip = false;
Vue.use(Avue);
Vue.use(ElementUI);
/* eslint-disable no-new */
new Vue({
  el: '#app',
  router,
  components: { App },
  template: '<App/>'
})

